<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>delayDialog</title>
    <link rel="stylesheet" href="css/reset.css"/>
    <link rel="stylesheet" href="css/all.css"/>
    <script src="js/jquery-3.1.1.min.js"></script>
    <script src="js/self.js"></script>
</head>
<body ontouchstart="">
<button onclick="showTipDialog('提示1', '提示1内容', cancelDialog, 1);">点击我弹出对话框</button>
<!-- toast start -->
<div class="theme-popover-mask">

</div>
<div id="dialog" class="dialog pf w100 h100">
    <section class="jz of bcf">
        <div id="dialogTitle" class="dialogTittle f17 tc jz">
                提示
        </div>
        <div id="dialogContent" class="content jz lh18 f14 of">

        </div>
        <div class="button w100 of clearfix">
            <button id="tipDialogCancel" onclick="cancelDialog()" class="fl cf f17" style="width: 50%;background: #CDCDCD;">取消</button>
            <button id="tipDialogSure" class="fl cf f17" style="width: 50%">确定</button>
        </div>
    </section>
</div>
<!-- toast end -->

<script>
    
    /**
     * 提示对话框
     * @param dialog
     * @param mask
     * @param func 点击确定执行的方法
     * @param flag 标识 0 显示两个按钮 1 显示确定按钮 2 显示取消
     * @constructor
     */
    function showTipDialog(title, content, func, flag) {
        var dgTitle = $('#dialogTittle');
        var dgContent = $('#dialogContent');
        dgTitle.text(title);
        dgContent.text(content);

        var btnCancel = $("#tipDialogCancel");
        var btnConfirm = $("#tipDialogSure");

        btnCancel.bind("click",cancelDialog);
        btnConfirm.bind("click",func);

        if (flag == 1) {
            btnCancel.hide(0);
            btnConfirm.show(0);
            btnConfirm.css('width', '100%');
        } else if (flag == 2) {
            console.log(btnCancel);
            btnConfirm.hide(0);
            btnCancel.show(0);
            btnCancel.css('width', '100%');
        } else {
            console.log(btnCancel);
            btnConfirm.show(0);
            btnCancel.show(0);
            btnConfirm.css('width', '50%');
            btnCancel.css('width', '50%');
        }

        var dialog = $('#dialog');
        var mask = $('#tipdialog_bg');
        mask.fadeIn();
        dialog.slideDown();
    }

    /**
     * 关闭提示对话框
     * @constructor
     */
    var cancelDialog = function () {
        var dialog = $('#dialog');
        var mask = $('#tipdialog_bg');

        mask.fadeOut();
        dialog.slideUp();
    }

</script>

</body>
</html>